<?php

namespace App\Admin\Controllers;

use App\Services\TransverseService;
use App\Transverse;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class TransverseContractController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '技术合同登记';
    protected $service;

    public function __construct(TransverseService $service)
    {
        $this->service = $service;
    }

    public function index(Content $content)
    {
        return $content
            ->title($this->title)
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Transverse());
//        $grid->header(function (Builder $builder) {
//            $year = request()->year ?: date('Y');
//            $query = Transverse::query()->whereYear('sign_date', $year)
//                ->where('tag', 1)
//                ->where('review_status', 1);
//            $count = $query->count();
//            $amount = $query->sum('amount');
//            $in_amount = TransverseBill::query()->whereYear('pay_date', $year)->sum('amount');
//            return view('admin.statistics.transverse-table-header', compact('year', 'count', 'amount', 'in_amount'));
//        });
        $this->service->header($grid);
        $this->service->gridColumn($grid, 1);
        $grid->model()->where('tag', 1);
        $grid->disableCreateButton();
        $grid->batchActions(function (Grid\Tools\BatchActions $actions) {
            $actions->disableDeleteAndHodeSelectAll();
        });
        $grid->disableActions();
        $grid->filter(function (Grid\Filter $filter) use ($grid) {
            $scopes = $filter->getScopes();
            foreach ($scopes as $key => $scope) {
                unset($scopes[$key]);
            }
        });
        return $grid;
    }

    protected function form()
    {
        $form = new Form(new Transverse());
        $form->text('contract_no','合同登记号');
        return $form;
    }
}
